package com.bienvenue.main.serviceApi;

import android.arch.lifecycle.MutableLiveData;

import com.bienvenue.main.httpService.ResponseObserver;
import com.bienvenue.main.httpService.RetrofitClient;
import com.bienvenue.main.model.AddSubAccountModel;
import com.bienvenue.main.model.AreaTreeModel;
import com.bienvenue.main.model.EnterprisePwdLoginModel;
import com.bienvenue.main.model.HotJobPositionModel;
import com.bienvenue.main.model.HotPromptModel;
import com.bienvenue.main.model.HttpBean;
import com.bienvenue.main.model.InformationPerfectionModel;
import com.bienvenue.main.model.JobManagerListModel;
import com.bienvenue.main.model.JobPostModel;
import com.bienvenue.main.model.PostJobModel;
import com.bienvenue.main.model.PwdLoginModel;
import com.bienvenue.main.model.ResumeInfoModel;
import com.bienvenue.main.model.SaveResumeModel;
import com.bienvenue.main.utils.SPUtils;

import java.io.File;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.Response;

/**
 * @ProjectName: Bienvenue
 * @Package: com.bienvenue.main.serviceApi
 * @ClassName: ServiceModel
 * @Description: java类作用描述
 * @Author: Mr.Chen
 * @CreateDate: 2020/9/11 9:34
 * @UpdateUser: Mr.Chen
 * @UpdateDate: 2020/9/11 9:34
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */


public class ServiceModel {

    static ServiceModel serviceModel;

    public static ServiceModel getServiceModel() {
        if (serviceModel == null) {
            serviceModel = new ServiceModel();
        }
        return serviceModel;
    }

    public UIChangeObservable uc = new UIChangeObservable();

    public class UIChangeObservable {
        /**
         * 这里加这一个code，算是预留，当成功的状态，或者错误状态变化比较多的时候，实用这个定义
         */
        public MutableLiveData<Integer> resultCode = new MutableLiveData<>();

        public MutableLiveData<String> resultMessage = new MutableLiveData<>();
    }


    public void setImg(String imgPath, ResponseObserver<HttpBean> responseObserver) {

        ApiService apiService = RetrofitClient.getInstance().create(ApiService.class);
        //funName
        String fileNameByTimeStamp = "RookieBro" + ".jpg";
        RequestBody funName = RequestBody.create(null, "ict_uploadpicture");
//path
        RequestBody path = RequestBody.create(null, "/uploadNews");
//appfile
        RequestBody appfile = RequestBody.create(null, fileNameByTimeStamp);
//上传图片的名字
        String fileName = "RookieBro" + ".jpg";
//图片文件
        File file = new File(imgPath);
        RequestBody requestFile = RequestBody.create(MediaType.parse("image/jpeg"), file);
/**
 *file部分，最终拼接成以下部分（注意“app_user_header”是后台定义好的，后台会用它作为key去查询你传的图片信息）：
 *Content-Disposition: form-data; name="app_user_header"; filename=fileNameByTimeStamp
 *Content-Type: image/jpeg
 *Content-Length: 52251(图片流字节数组的长度，底层的Okhttp帮我们计算了)
 *...(文件流)
 */
        MultipartBody.Part body = MultipartBody.Part.createFormData("file", fileName, requestFile);
        RetrofitClient.getInstance().execute(apiService.setImg(body), responseObserver);
    }



    public void onRegister(String userName, String pwd, String phone, ResponseObserver<HttpBean> responseObserver) {
        ApiService apiService = RetrofitClient.getInstance().create(ApiService.class);

        RetrofitClient.getInstance().execute(apiService.register(userName, pwd, phone), responseObserver);
    }

    public void onPwdLogin(String userName, String pwd, ResponseObserver<PwdLoginModel> responseObserver) {
        ApiService apiService = RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.onPwdLogin(userName, pwd), responseObserver);
    }

    public void onSuperCode(String phone, ResponseObserver<HttpBean> observer) {
        ApiService apiService = RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.onSuperCode(phone), observer);
    }

    public void onVaildCompanyName(String commpanyName,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.onVaildCompanyName(commpanyName),responseObserver);
    }

    public void onEnterpriseRegister(String companyName,String phone,String password,String code,String companyLogin,String logo,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.onEnterpriseRegister(companyName,phone,password,code,companyLogin,logo),responseObserver);
    }
    public void onEnterprisePwdLogin(String companyName,String pwd,ResponseObserver<EnterprisePwdLoginModel> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.onEnterprisePwdLogin(companyName,pwd),responseObserver);
    }

    public void onEnterpriseCodeLogin(String phone,String code,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.onEnterpriseCodeLogin(phone,code),responseObserver);
    }

    public void onCodeLogin(String phone,String code,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.onCodeLogin(phone, code),responseObserver);
    }

    public void getTree(ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.getTree(),responseObserver);
    }
    public void getTreeArea(ResponseObserver<AreaTreeModel> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.getTreeArea(),responseObserver);
    }

    public void getListByTypeWorkYears( ResponseObserver<JobPostModel> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.getListByTypeWorkYears( ),responseObserver);
    }

    public void getListByTypePositionSalary(ResponseObserver<JobPostModel> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.getListByTypePositionSalary( ),responseObserver);
    }

    public void getListByTypeEducate(ResponseObserver<JobPostModel> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.getListByTypeEducate( ),responseObserver);
    }

    public void getListByCorporateWelfare(ResponseObserver<JobPostModel> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.getListByCorporateWelfare( ),responseObserver);
    }

    public void onPostJob(PostJobModel model,ResponseObserver<HttpBean> beanResponseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.onPostJob(model),beanResponseObserver);
    }

    public void onGetJobList(ResponseObserver<JobManagerListModel> responseObserver){
        String token=SPUtils.getString("token");
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.onGetJobList(token),responseObserver);
    }

    public void putDocOrPdf(String imgPath,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService = RetrofitClient.getInstance().create(ApiService.class);
        //funName
        String fileNameByTimeStamp = "RookieBro" + ".pdf";
        RequestBody funName = RequestBody.create(null, "ict_uploadpicture");
//path
        RequestBody path = RequestBody.create(null, "/uploadNews");
//appfile
        RequestBody appfile = RequestBody.create(null, fileNameByTimeStamp);
//上传图片的名字
        String fileName = "RookieBro" + ".pdf";
//图片文件
        File file = new File(imgPath);
        RequestBody requestFile = RequestBody.create(MediaType.parse("application/pdf"), file);
/**
 *file部分，最终拼接成以下部分（注意“app_user_header”是后台定义好的，后台会用它作为key去查询你传的图片信息）：
 *Content-Disposition: form-data; name="app_user_header"; filename=fileNameByTimeStamp
 *Content-Type: image/jpeg
 *Content-Length: 52251(图片流字节数组的长度，底层的Okhttp帮我们计算了)
 *...(文件流)
 */
        MultipartBody.Part body = MultipartBody.Part.createFormData("file", fileName,requestFile);
        RetrofitClient.getInstance().execute(apiService.putDocOrPdf(body), responseObserver);
    }

    public void onSaveResumeWorkingYears(SaveResumeModel.WorkYearsModel model,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.onSaveResumeWorkingYears(model),responseObserver);
    }

    public void onSaveResumeEducation(SaveResumeModel.EducationModel model,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.onSaveResumeEducation(model),responseObserver);
    }
    public void onSaveResumeProjectExperience(SaveResumeModel.ProjectExperienceModel model,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.onSaveResumeProjectExperience(model),responseObserver);
    }

    public void onSaveResumeJobHunting(SaveResumeModel.JobHuntingModel model,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.onSaveResumeJobHunting(model),responseObserver);
    }

    public void getListByTimeArrival(ResponseObserver<JobPostModel> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.getListByTimeArrival(),responseObserver);
    }

    public void getListByWorkStatus(ResponseObserver<JobPostModel> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.getListByWorkStatus(),responseObserver);
    }

    public void onSaveResumeCertificate(SaveResumeModel.CertificateModel model,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.onSaveResumeCertificate(model),responseObserver);
    }

    public void onSaveResumeProgress(SaveResumeModel.ProgressModel model,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.onSaveResumeProgress(model),responseObserver);
    }

    public void getResumeInfo(String userId,ResponseObserver<ResumeInfoModel> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.getResumeInfo(userId),responseObserver);

    }

    public  void putResumeInfo(SaveResumeModel.ResumeInfoModel model,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.putResumeInfo(model),responseObserver);
    }

    public void deleteResumeJobHunting(String userId,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.deleteResumeJobHunting(userId),responseObserver);
    }
    public void deleteResumeExperience(String userId, ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.deleteResumeExperience(userId),responseObserver);
    }
    public void deleteResumeWork(String userId,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.deleteResumeWork(userId),responseObserver);
    }
    public void deleteEducation(String userId,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.deleteEducation(userId),responseObserver);
    }

    public void deleteProgress(String id,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.deleteProgress(id),responseObserver);
    }

    public void popularCompanies(int page,int limit,ResponseObserver<HotPromptModel> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.popularCompanies(page,limit),responseObserver);
    }

    public void getPopularPositions(int page,int limit,ResponseObserver<HotJobPositionModel> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.getPopularPositions(page,limit),responseObserver);
    }

    public void deleteCertificate(String id,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.deleteCertificate(id),responseObserver);
    }

    public void enterpriseLoginOut(String id,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.enterpriseLoginOut(id),responseObserver);
    }

    public void personalLoginOut(String id,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.personalLoginOut(id),responseObserver);
    }

    public void getListByCompanySize(ResponseObserver<JobPostModel> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.getListByCompanySize(),responseObserver);
    }

    public void getListByTypeCompanyNature(ResponseObserver<JobPostModel> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.getListByTypeCompanyNature(),responseObserver);
    }

    public void getListByTypeIndustry(ResponseObserver<JobPostModel> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.getListByTypeIndustry(),responseObserver);
    }
    public void putInformationPerfection(HttpBean.ParamRegisterBean bean,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.putInformationPerfection(bean),responseObserver);
    }

    public void putSubAccount(String phone,String code, String companyId,String password,String userName,ResponseObserver<HttpBean> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.putSubAccount(phone,code,companyId,password,userName ),responseObserver);
    }

    public void getInformationPerfection(String companyId,ResponseObserver<InformationPerfectionModel> responseObserver){
        ApiService apiService=RetrofitClient.getInstance().create(ApiService.class);
        RetrofitClient.getInstance().execute(apiService.getInformationPerfection(companyId),responseObserver);
    }




}
